<!--
  -    Copyright (c) 2018-2025, infomng All rights reserved.
  -
  - Redistribution and use in source and binary forms, with or without
  - modification, are permitted provided that the following conditions are met:
  -
  - Redistributions of source code must retain the above copyright notice,
  - this list of conditions and the following disclaimer.
  - Redistributions in binary form must reproduce the above copyright
  - notice, this list of conditions and the following disclaimer in the
  - documentation and/or other materials provided with the distribution.
  - Neither the name of the pig4cloud.com developer nor the names of its
  - contributors may be used to endorse or promote products derived from
  - this software without specific prior written permission.
  - Author: infomng
  -->
<template>
  <basic-container>
    <div  v-loading="loading"  :element-loading-text="loadingText">
      <el-tabs v-model="activeName">
        <el-tab-pane label="插回损检测" name="first" :style="{ width: '100%'}">
          <div class="execution" v-loading="loading"  :element-loading-text="loadingText">
            <basic-container>
              <avue-crud
                ref="crud"
                :page.sync="page"
                :data="tableData"
                :permission="permissionList"
                :table-loading="tableLoading"
                :option="tableOption"
                @search-change="searchChange"
                @refresh-change="refreshChange"
                @size-change="sizeChange"
                @current-change="currentChange"
                @row-update="handleUpdate"
                @row-save="handleSave"
                @row-del="handleDel">
<!--                <template slot="menuLeft">
                  <el-button
                    class="filter-item"
                    plain
                    type="primary"
                    size="small"
                    icon="el-icon-download"
                    @click="exportExcel">导出
                  </el-button>
                </template>-->
              </avue-crud>
            </basic-container>
          </div>
        </el-tab-pane>
        <el-tab-pane label="干涉检测" name="second" :style="{ width: '100%'}">
          <div class="execution"  v-loading="loading"  :element-loading-text="loadingText">
            <basic-container>
              <avue-crud
                ref="crud"
                :page.sync="page2"
                :data="tableData2"
                :permission="permissionList2"
                :table-loading="tableLoading2"
                :option="tableOption2"
                @search-change="searchChange2"
                @refresh-change="refreshChange2"
                @size-change="sizeChange2"
                @current-change="currentChange2">
<!--                <template slot="menuLeft">
                  <el-button
                    class="filter-item"
                    plain
                    type="primary"
                    size="small"
                    icon="el-icon-download"
                    @click="exportExcel2">导出
                  </el-button>
                </template>-->
              </avue-crud>
            </basic-container>
          </div>
        </el-tab-pane>

      </el-tabs>
    </div>


  </basic-container>

</template>

<script>
import { fetchList, addObj, putObj, delObj } from '@/api/workorder/opltshhs'
import { tableOption, tableOption2 } from '@/const/crud/workorder/reportdatadetails'
import { mapGetters } from 'vuex'
import { fetchList as fetchList2} from '@/api/workorder/interferometermtpro'

export default {
  name: 'opltshhs',
  data() {
    return {
      searchForm: {},
      tableData: [],
      page: {
        total: 0, // 总页数
        currentPage: 1, // 当前页数
        pageSize: 10 // 每页显示多少条
      },
      tableLoading: false,
      tableOption: tableOption,
      loading: false, // 加载状态
      loadingText: '正在导出...', // 加载提示文本
      activeName: 'first',
      searchForm2: {},
      tableData2: [],
      page2: {
        total: 0, // 总页数
        currentPage: 1, // 当前页数
        pageSize: 10 // 每页显示多少条
      },
      tableLoading2: false,
      tableOption2: tableOption2,
      loading2: false, // 加载状态
    }
  },
  computed: {
    ...mapGetters(['permissions']),
    permissionList() {
      return {
        addBtn: this.vaildData(this.permissions.workorder_opltshhs_add, false),
        delBtn: this.vaildData(this.permissions.workorder_opltshhs_del, false),
        editBtn: this.vaildData(this.permissions.workorder_opltshhs_edit, false)
      }
    },
    permissionList2() {
      return {
        addBtn: this.vaildData(this.permissions.workorder_opltshhs_add, false),
        delBtn: this.vaildData(this.permissions.workorder_opltshhs_del, false),
        editBtn: this.vaildData(this.permissions.workorder_opltshhs_edit, false)
      }
    }
  },
  methods: {
    // 列表查询
    getList(page, params) {
      this.tableLoading = true
      if(!this.validatenull(this.searchForm.sysTime)){
        this.searchForm.startTime = this.searchForm.sysTime[0];
        this.searchForm.endTime =this.searchForm.sysTime[1];
      }
      fetchList(Object.assign({
        current: page.currentPage,
        size: page.pageSize,
      }, params, this.searchForm)).then(response => {
        this.tableData = response.data.data.records
        this.page.total = response.data.data.total
        this.tableLoading = false
      }).catch(() => {
        this.tableLoading = false
      })
    },
    // 列表查询
    getList2(page, params) {
      this.tableLoading2 = true
      if (!this.validatenull(this.searchForm2.sysTime)) {
        this.searchForm2.startTime = this.searchForm2.sysTime[0]
        this.searchForm2.endTime = this.searchForm2.sysTime[1]
      }
      //由于数据库中工单没有-，所以需要去除查询
      if (!this.validatenull(this.searchForm2.fileName)) {
        this.searchForm2.fileName = this.searchForm2.fileName.replaceAll("-", "") // 直接替换所有 "-"
      }
      fetchList2(Object.assign({
        current: page.currentPage,
        size: page.pageSize,
      }, params, this.searchForm2)).then(response => {
        this.tableData2 = response.data.data.records
        this.page2.total = response.data.data.total
        this.tableLoading2 = false
      }).catch(() => {
        this.tableLoading2 = false
      })
    },
    // 删除
    handleDel: function(row, index) {
      this.$confirm('是否确认删除ID为' + row.$pk.lowerAttrName, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(function() {
        return delObj(row.$pk.lowerAttrName)
      }).then(data => {
        this.$message.success('删除成功')
        this.getList(this.page)
      })
    },
    // 更新
    handleUpdate: function(row, index, done, loading) {
      putObj(row).then(data => {
        this.$message.success('修改成功')
        done()
        this.getList(this.page)
      }).catch(() => {
        loading()
      })
    },
    // 保存
    handleSave: function(row, done, loading) {
      addObj(row).then(data => {
        this.$message.success('添加成功')
        done()
        this.getList(this.page)
      }).catch(() => {
        loading()
      })
    },
    // 每页条数改变事件
    sizeChange(pageSize) {
      this.page.pageSize = pageSize
      this.getList(this.page);
    },
    // 当前页发生改变事件
    currentChange(current) {
      this.page.currentPage = current
      this.getList(this.page);
    },
    // 查询事件
    searchChange(form, done) {
      this.searchForm = form
      this.page.currentPage = 1
      this.getList(this.page, form)
      done()
    },
    // 刷新事件
    refreshChange() {
      this.getList(this.page)
    },
    //  导出excel
    exportExcel() {
      //判断this.searchForm不为空
      if(!this.validatenull(this.searchForm.docNo)) {
         this.loading = true; // 开始加载
         this.downBlobFile('/workorder/opltshhs/export', this.searchForm, this.searchForm.docNo+'插回损数据.xlsx')
           .then(() => {
             this.loading = false; // 结束加载
             this.$message.success('导出成功')
           }).catch(() => {
             this.loading = false; // 结束加载
             this.$message.error('导出失败')
           })
      }else {
        this.$message.warning('请输入工单号后再导出')
      }
    },
    // 每页条数改变事件
    sizeChange2(pageSize) {
      this.page2.pageSize = pageSize
      this.getList2(this.page);
    },
    // 当前页发生改变事件
    currentChange2(current) {
      this.page2.currentPage = current
      this.getList2(this.page);
    },
    // 查询事件
    searchChange2(form, done) {
      this.searchForm2 = form
      this.page2.currentPage = 1
      this.getList2(this.page, form)
      done()
    },
    // 刷新事件
    refreshChange2() {
      this.getList2(this.page)
    },
    //  导出excel
    exportExcel2() {
      //判断this.searchForm不为空
      if (!this.validatenull(this.searchForm2.description)) {
        this.loading2 = true; // 开始加载
        this.downBlobFile('/workorder/interferometermtpro/export', this.searchForm2, this.searchForm2.description + '干涉数据.xlsx')
          .then(() => {
            this.loading2 = false; // 结束加载
            this.$message.success('导出成功')
          }).catch(() => {
          this.loading2 = false; // 结束加载
          this.$message.error('导出失败')
        })
      } else {
        this.$message.warning('请输入工单号后再导出')
      }
    }
  }
}
</script>
